﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace UI
{
    public class RushEliteBossBuyTimePanel : MonoBehaviour
    {
        public UILabel detailLabel;
        public UILabel resetNumLabel;

        public RushEliteBossPage rushEliteBossPage;

        public List<UITweener> tweeners;

        int costNum;

        public void Enter(int leftTime, int costNum)
        {
            this.costNum = costNum;
            detailLabel.text = string.Format(TableTextBlo.GetText("rush_boss_buy_time_detail"), costNum);
            resetNumLabel.text = leftTime.ToString();
            gameObject.SetActive(true);
            foreach (var tweener in tweeners)
            {
                if (tweener != null)
                {
                    tweener.ResetToBeginning();
                    tweener.PlayForward();
                }
            }
        }

        public void Exit()
        {
            gameObject.SetActive(false);
        }

        public void OnConfirmButtonClick()
        {
            if (StaticData.playerData.diamond < costNum)
            {
                BoxManager.CreatePopupTextBox(TableTextBlo.GetText("diamond_lack"));
                return;
            }

            ProtoBuf.Message.CSRushEliteBossBuyTime msg = new ProtoBuf.Message.CSRushEliteBossBuyTime();
            NetAPI.SendHttp(ProtoBuf.Message.OpDefine.CSRushEliteBossBuyTime, msg, (pack, b) =>
            {
                ProtoBuf.Message.SCRushEliteBossBuyTime _msg = pack.kBody as ProtoBuf.Message.SCRushEliteBossBuyTime;
                StaticData.playerData.Delete(_msg.cost);
                BoxManager.CreatePopupTextBox(TableTextBlo.GetText("buy_success"));
                Exit();
                rushEliteBossPage.OnCoverPageRemove();
            });
        }

        public void OnCancelButtonClick()
        {
            Exit();
        }


    }
}